{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 5.3 \u4f7f\u7528\u5176\u4ed6\u5206\u9694\u7b26\u6216\u884c\u7ec8\u6b62\u7b26\u6253\u5370\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u60f3\u4f7f\u7528 print() \u51fd\u6570\u8f93\u51fa\u6570\u636e\uff0c\u4f46\u662f\u60f3\u6539\u53d8\u9ed8\u8ba4\u7684\u5206\u9694\u7b26\u6216\u8005\u884c\u5c3e\u7b26\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u53ef\u4ee5\u4f7f\u7528\u5728 print() \u51fd\u6570\u4e2d\u4f7f\u7528 sep \u548c end \u5173\u952e\u5b57\u53c2\u6570\uff0c\u4ee5\u4f60\u60f3\u8981\u7684\u65b9\u5f0f\u8f93\u51fa\u3002\u6bd4\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print('ACME', 50, 91.5)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print('ACME', 50, 91.5, sep=',')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print('ACME', 50, 91.5, sep=',', end='!!\\n')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f7f\u7528 end \u53c2\u6570\u4e5f\u53ef\u4ee5\u5728\u8f93\u51fa\u4e2d\u7981\u6b62\u6362\u884c\u3002\u6bd4\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "for i in range(5):\n    print(i)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "for i in range(5):\n    print(i, end=' ')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5f53\u4f60\u60f3\u4f7f\u7528\u975e\u7a7a\u683c\u5206\u9694\u7b26\u6765\u8f93\u51fa\u6570\u636e\u7684\u65f6\u5019\uff0c\u7ed9 print() \u51fd\u6570\u4f20\u9012\u4e00\u4e2a sep \u53c2\u6570\u662f\u6700\u7b80\u5355\u7684\u65b9\u6848\u3002\n\u6709\u65f6\u5019\u4f60\u4f1a\u770b\u5230\u4e00\u4e9b\u7a0b\u5e8f\u5458\u4f1a\u4f7f\u7528 str.join() \u6765\u5b8c\u6210\u540c\u6837\u7684\u4e8b\u60c5\u3002\u6bd4\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print(','.join(('ACME','50','91.5')))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "str.join() \u7684\u95ee\u9898\u5728\u4e8e\u5b83\u4ec5\u4ec5\u9002\u7528\u4e8e\u5b57\u7b26\u4e32\u3002\u8fd9\u610f\u5473\u7740\u4f60\u901a\u5e38\u9700\u8981\u6267\u884c\u53e6\u5916\u4e00\u4e9b\u8f6c\u6362\u624d\u80fd\u8ba9\u5b83\u6b63\u5e38\u5de5\u4f5c\u3002\u6bd4\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "row = ('ACME', 50, 91.5)\nprint(','.join(row))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print(','.join(str(x) for x in row))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u5f53\u7136\u53ef\u4ee5\u4e0d\u7528\u90a3\u4e48\u9ebb\u70e6\uff0c\u53ea\u9700\u8981\u50cf\u4e0b\u9762\u8fd9\u6837\u5199\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print(*row, sep=',')"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}